package com.ruoyi.zhoubao.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhoubao.domain.ABase;
import com.ruoyi.zhoubao.service.IABaseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * abaseController
 * 
 * @author ruoyi
 * @date 2025-10-24
 */
@Controller
@RequestMapping("/zhoubao/base")
public class ABaseController extends BaseController
{
    private String prefix = "zhoubao/base";

    @Autowired
    private IABaseService aBaseService;

    @RequiresPermissions("zhoubao:base:view")
    @GetMapping()
    public String base()
    {
        return prefix + "/base";
    }

    /**
     * 查询abase列表
     */
   // @RequiresPermissions("zhoubao:base:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ABase aBase)
    {
        startPage();
        List<ABase> list = aBaseService.selectABaseList(aBase);
        return getDataTable(list);
    }

    @PostMapping("/listcount")
    @ResponseBody
    public TableDataInfo listcount(ABase aBase)
    {
        startPage();
        List<ABase> list = aBaseService.selectABaseListCount(aBase);
        return getDataTable(list);
    }

    // @RequiresPermissions("zhoubao:base:list")
    @PostMapping("/list2")
    @ResponseBody
    public TableDataInfo list2(ABase aBase)
    {
        startPage();
        List<ABase> list = aBaseService.selectABaseList2(aBase);
        return getDataTable(list);
    }




    /**
     * 导出abase列表
     */
    @RequiresPermissions("zhoubao:base:export")
    @Log(title = "abase", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ABase aBase)
    {
        List<ABase> list = aBaseService.selectABaseList(aBase);
        ExcelUtil<ABase> util = new ExcelUtil<ABase>(ABase.class);
        return util.exportExcel(list, "abase数据");
    }

    /**
     * 新增abase
     */
    @RequiresPermissions("zhoubao:base:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存abase
     */
    @RequiresPermissions("zhoubao:base:add")
    @Log(title = "abase", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ABase aBase)
    {
        return toAjax(aBaseService.insertABase(aBase));
    }

    /**
     * 修改abase
     */
    @RequiresPermissions("zhoubao:base:edit")
    @GetMapping("/edit/{name}")
    public String edit(@PathVariable("name") String name, ModelMap mmap)
    {
        ABase aBase = aBaseService.selectABaseByName(name);
        mmap.put("aBase", aBase);
        return prefix + "/edit";
    }

    /**
     * 修改保存abase
     */
    @RequiresPermissions("zhoubao:base:edit")
    @Log(title = "abase", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ABase aBase)
    {
        return toAjax(aBaseService.updateABase(aBase));
    }

    /**
     * 删除abase
     */
    @RequiresPermissions("zhoubao:base:remove")
    @Log(title = "abase", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aBaseService.deleteABaseByNames(ids));
    }
    
    /**
     * 查询个人总需求数和本周新增需求数
     */
    @PostMapping("/listPersonal")
    @ResponseBody
    public TableDataInfo listPersonal(ABase aBase)
    {
        startPage();
        List<ABase> list = aBaseService.selectPersonalDemandList(aBase);
        return getDataTable(list);
    }
    
    /**
     * 查询个人近五周每周新增需求数
     */
    @PostMapping("/listWeeklyDemands")
    @ResponseBody
    public TableDataInfo listWeeklyDemands(ABase aBase)
    {
        startPage();
        List<ABase> list = aBaseService.selectWeeklyDemandsList(aBase);
        return getDataTable(list);
    }
}